var pageListUrl = basePath + "/sys/report/teacherChangeCourse/page";
var dataGrid;
var schoolId = $("#userSchoolId").val();

$(function() {
	initSchoolIdValue();
	loadData();
});

function loadData() {
	dataGrid = $('#notice').datagrid({
		url : pageListUrl,
		toolbar: '#tb',
		fit : true,
		fitColumns : true,
		border : true,
		pagination : true,
		idField : 'id',
		pageSize : config.pageSize,
		autoRowHeight : 140,
		pageList : config.pageList,
		queryParams : {
			status: $("#status").val(),
			applyStartDate: $("#applyStartDate").val(),
			applyEndDate: $("#applyEndDate").val(),
			schoolId: schoolId
		},
		nowrap : true,
		striped : true,
		rownumbers : true,
		columns : [ [ 
		{
			field : 'id',
			align : "center",
			width : 10,
			checkbox : true
		}, 
		{ 
			field : 'applyTeacherName',
			title : '申请老师',
			width : 10,
			resizable : true,
			align : "center"
		}, 
		{
			field : 'grade',
			title : '班级',
			width : 15,
			align : "center",
			formatter : function(value, row, index) {
        		return row.gradeName + "("+row.clazz+")班";
        	}
		},
		{
			field : 'subjectName',
			title : '课程',
			width : 10,
			align : "center"
		},
		{
			field : 'optionTypeText',
			title : '调代看课类型',
			width : 15,
			align : "center"
		},
		{
			field : 'currLesson',
			title : '申请日期节次',
			width : 25,
			align : "center",
			formatter : function(value, row, index) {
        		return getTime(row.courseDate, "yyyy-MM-dd") + row.lesson;
        	}
		},
		{
			field : 'exchangeTeacherName',
			title : '调代看课教师',
			width : 15,
			align : "center"
		},
		{
			field : 'exchangeSubjectName',
			title : '调课课程',
			width : 15,
			align : "center"
		},
		{
			field : 'exchangeCourseDate',
			title : '调课日期节次',
			width : 30,
			align : "center",
			formatter : function(value, row, index) {
        		return getTime(row.exchangeCourseDate, "yyyy-MM-dd") + nullToEmpty(row.exchangeLesson);
        	}
		},
		{
			field : 'reason',
			title : '是由',
			width : 30,
			align : "center"
		},
		{
			field : 'applyStatusText',
			title : '审批状态',
			width : 20,
			align : "center"
		},
		{
			field : 'approverName',
			title : '审批人',
			width : 20,
			align : "center"
		},
		{
			field : 'createTime',
			title : '申请时间',
			width : 20,
			align : "center",
			formatter : function(value, row, index) {
        		return getTime(value, "yyyy-MM-dd hh:mm:ss");
        	}
		}
      ] ]
	});
}
function reload() {
	dataGrid.datagrid("clearSelections");
	searchForm("searchForm");
}

function searchForm(formId) {
	dataGrid.datagrid('load', $.serializeObject($('#' + formId)));
}
function resetForm(formId) {
	$("#" + formId)[0].reset();
	$("#applyStartDate").datebox('setValue', '');
	$("#applyEndDate").datebox('setValue', '');
}
function exportToExcel(searchForm,exportUrl) {
	$("#" + searchForm).attr('action',exportUrl); 
	$("#" + searchForm).submit();  
}